<?php

/**
 * @author AnhVu, PhatPham
 * @copyright 2013
 */
class AnswerTemplatemodel extends CI_Model {
    var $template_id;   //dtid
    var $question_id;   //qid
    var $option_type;   //otype
    var $view_order;    //vorder
    var $label; //label
    var $exception; //exc
    var $sub_question;  //subq
    var $is_deleted;
    var $created_by_user_id;    //userid
    var $created_on_date;
    var $last_modified_by_user_id;  //userid
    var $last_modified_on_date;
    
    function __construct()
    {
        // Call the Model constructor
        $this->load->database();
    }
    //Author PhatPham
    //Get answer templates list of question
    function get_answer_templates_list($qid){
        $this->db->order_by('view_order', 'asc');
        $query = $this->db->get_where('sur_answer_template', array('question_id' => $qid, 'is_deleted' => false));
        return $query;
    }
    //Author PhatPham
    //Create answer template
    function create_answer_template($atid, $qid, $otype, $atvorder, $label, $exc, $subq, $userid){
        $data = array(
               'template_id' => $atid,
               'question_id' => $qid,
               'option_type' => $otype,
               'view_order' => $atvorder,
               'label' => $label,
               'exception' => $exc,
               'sub_question' => $subq,
               'is_deleted' => false,
               'created_by_user_id' => $userid,
               'created_on_date' => mdate('%m/%d/%Y %H:%i:%s',now())
            );
        $this->db->insert('sur_answer_template', $data);
    }
	//Author PhatPham
    //Edit answer template
    function edit_answer_template($atid, $otype, $atvorder, $label, $exc, $subq, $userid){
        $data = array(
               'option_type' => $otype,
               'view_order' => $atvorder,
               'label' => $label,
               'exception' => $exc,
               'sub_question' => $subq,
               'last_modified_by_user_id' => $userid,
               'last_modified_on_date' => mdate('%m/%d/%Y %H:%i:%s',now())
            );
		$this->db->where('template_id', $atid);
        $this->db->update('sur_answer_template', $data);
    }
    //Author: AnhVu
    //delete answer templates by question id
    function delete_question_answer_templates($qid, $userid){
        $data = array(
               'is_deleted' => true,
               'last_modified_by_user_id' => $userid,
               'last_modified_on_date' => mdate('%m/%d/%Y %H:%i:%s',now())
            );
        $this->db->where('question_id', $qid);
        $this->db->update('sur_answer_template', $data);
    }
    //Author: PhatPham
    //Delete 1 answer template
    function delete_answer_template($atid, $userid){
        $data = array(
               'is_deleted' => true,
               'last_modified_by_user_id' => $userid,
               'last_modified_on_date' => mdate('%m/%d/%Y %H:%i:%s',now())
            );
        $this->db->where('template_id', $atid);
        $this->db->update('sur_answer_template', $data);
    }
}
?>